import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ty_smart_watch/ble/connected_device_controller.dart';
import 'package:ty_smart_watch/common/images_url.dart';
import 'package:ty_smart_watch/db/device_in_db_controller.dart';
import 'package:ty_smart_watch/page/me/controller/user_detail_controller.dart';
import 'package:ty_smart_watch/route/routes.dart';

class UserTitle extends StatelessWidget {
  final DeviceInDbController _dbController = Get.find();

  @override
  Widget build(BuildContext context) {
    UserDetailController _controller = Get.find();

    return GestureDetector(
      onTap: () {
        print('点击了个人信息');
        Get.toNamed(Routes.userDetailPage);
      },
      child: Container(
          // alignment: Alignment.center,
          margin: const EdgeInsets.only(top: 20),
          // margin: const EdgeInsets.fromLTRB(10, 20, 10, 0),
          padding: const EdgeInsets.fromLTRB(30, 30, 0, 30),
          decoration: const BoxDecoration(
            //背景图片
            image: DecorationImage(image: AssetImage(SPORT_DASHBOARD_BACKROUND), fit: BoxFit.fill),
            //圆角半径
            borderRadius: BorderRadius.all(Radius.circular(12.0)),
            //边框线宽、颜色
            // border: Border.all(width: 1.0, color: Colors.blue),
            // 线性渐变，分别设置渐变的颜色，起始点
            // gradient: LinearGradient(
            //     begin: Alignment.topLeft,
            //     end: Alignment.bottomRight,
            //     colors: [Colors.white, Colors.lightBlueAccent]),
          ),
          child: Row(
            children: [
              Image.asset(SETTING_AVATAR, width: 60, height: 60),
              const SizedBox(width: 20),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Obx(
                    () => Text(
                      _controller.userName.value,
                      style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                    ),
                  ),
                  GestureDetector(
                    onTap: () {
                      Get.toNamed(Routes.connectedDeviceListPage);
                    },
                    child: Text('${_dbController.deviceList.value.length}个智能设备'),
                  )
                ],
              )
            ],
          )),
    );
  }
}
